package com.atguigu.day15.stringbudder;

import org.junit.Test;

public class StringAndStringBuffer {
    @Test
    public void test01(){

      //  testString();
       // testStringBffer();
        testStringBuilder();
    }

    private void testStringBuilder() {
        long start = System.currentTimeMillis();
        StringBuilder sbf = new StringBuilder();
        for (int i = 0; i < 10_0000; i++) {
            sbf.append(i);

        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);//5
    }

    private void testStringBffer() {
        long start = System.currentTimeMillis();
       StringBuffer sbf = new StringBuffer();
        for (int i = 0; i < 10_0000; i++) {
          sbf.append(i);

        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);//9  1s=1000ms
    }

    private void testString() {
        long start = System.currentTimeMillis();
        String s = "";
        for (int i = 0; i < 10_0000; i++) {
            s+=i;

        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);//23211 1s=1000ms
    }
}
